import router from './router'
import store from './store'

router.beforeEach(async (to, from, next) => {
    // console.log(from,'from');
    // console.log(to,'to');
    // 设置页面标题
    document.title = to.meta.title || '电商系统表格';
    if(to.path === '/AfterSales/Operate' && from.path === '/'){
        await store.dispatch('ResetState')
    }
    // 判断设备pc还是wap
    const isMobile = window.matchMedia("(max-width: 767px)").matches;
    if(isMobile) await store.dispatch('SetIsMobile', 'wap')
    else await store.dispatch('SetIsMobile', 'pc')
    if(to.path === '/AfterSales/Operate' && to.query.userId) {
        await store.dispatch('SetUserId', to.query.userId)
        next()
    }else if(store.state.UserId.length){
        next()
    }else{
      next()
      // window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww60f7a067df04bf8a&redirect_uri=https%3A%2F%2Fqw.ccpluss.com%2FgetUserId&response_type=code&scope=snsapi_privateinfo&state=STATE&agentid=1000008#wechat_redirect'
    }
})
